Skip to main content

object

object is a type just like string is a type.

However, objects are effectively data structures since they store, manage and modify data - specifically key-value pairs.

info

Objects are quite important to learn and understand as they are the top level, the pinnacle type.

Almost everything is derived from the object object in Hedgehog Script.

Let's discuss the constructor for object - which creates objects:

  • If the input is null or undefined you will get an empty object. If the argument is an object itself it will return itself.

  • Otherwise, the constructor will return an object of a type that corresponds to the given argument.

Let's view an example of creating objects:

info

There is no direct method to delete object properties like Map (which has Map.delete()) for example.

Rather, one must use the delete operator: delete Object.property;

There are quite a few methods, static or instance, for object. Let's point out some of them:

  • Object() - the constructor, takes the input and makes it an object.

  • (static) Object.entries() - returns an array with all [key, value] pairs of a given object.

  • (static) Object.seal() - prevents other code from deleting properties of an object.

  • (instance) Object.hasOwnProperty() - returns true or false based on whether the object has the direct property.

  • (instance) Object.toString() - returns a String representation of the object.

Objects can be quite a complex topic. They are fundamental and have a long list of methods and details.

tip

If one is curious to learn more, check out Objects for more info.